package com.zoe.onelink.core.autoconfigure;

import com.ulisesbocchio.jasyptspringboot.properties.JasyptEncryptorConfigurationProperties;
import com.zoe.onelink.core.async.OnelinkContextTaskDecorator;
import com.zoe.onelink.core.check.HttpClientEnvironmentChecker;
import com.zoe.onelink.core.check.JVMEnvironmentChecker;
import com.zoe.onelink.core.config.DruidStringEncryptor;
import com.zoe.onelink.core.exception.handler.GlobalExceptionHandler;
import com.zoe.onelink.core.property.FastJsonParserProperties;
import com.zoe.onelink.core.property.OnelinkProperties;
import com.zoe.onelink.core.web.converter.WebDateConverter;
import com.zoe.onelink.core.web.validation.aspect.ParameterAspect;
import com.zoe.onelink.plugin.check.EnvironmentChecker;
import com.zoe.onelink.util.SpringUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.task.TaskDecorator;

import java.util.Date;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-08-21
 */
@Configuration(proxyBeanMethods = false)
@Import({SpringUtil.class, GlobalExceptionHandler.class})
@EnableConfigurationProperties({OnelinkProperties.class, FastJsonParserProperties.class, JasyptEncryptorConfigurationProperties.class})
public class OnelinkAutoConfiguration {

    @Bean
    public Converter<String, Date> webDateConverter() {
        return new WebDateConverter();
    }

    @Bean
    public ParameterAspect parameterAspect() {
        return new ParameterAspect();
    }

    @Bean
    public DruidStringEncryptor druidStringEncryptor(JasyptEncryptorConfigurationProperties jasyptEncryptorConfigurationProperties) {
        return new DruidStringEncryptor(jasyptEncryptorConfigurationProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public TaskDecorator onelinkContextDecorator() {
        return OnelinkContextTaskDecorator.getInstance();
    }

    @Bean
    public EnvironmentChecker httpClientPropertyChecker() {
        return new HttpClientEnvironmentChecker();
    }

    @Bean
    public JVMEnvironmentChecker jvmEnvironmentChecker() {
        return new JVMEnvironmentChecker();
    }

}
